import pyautogui
import time
import numpy as np
import cv2
import platform
import subprocess

time.sleep(2)

pyautogui.PAUSE = 0.5 # 设置自动化操作时间间隔

print('开始')

def delete_chat_info():
    '''删除聊天信息'''

    pyautogui.screenshot() # 屏幕截图
    # 定位聊天气泡图
    chat_bubble = pyautogui.locateCenterOnScreen('people.png')

    if not chat_bubble:
        print('定位聊天气泡图失败')
        return
    # 聊天气泡图右移120像素则是联系人的坐标位置
    x = chat_bubble[0] + 120
    y = chat_bubble[1]
    # 右键点击，让微信弹窗删除列表框
    pyautogui.rightClick(x, y)

    pyautogui.screenshot()
    # 定位删除按钮
    delete_button = pyautogui.locateCenterOnScreen('delete.png')
    if not delete_button:
        delete_button = pyautogui.locateCenterOnScreen('delete2.png')
        if not delete_button:
            print('定位删除按钮失败')
            return
    # 模拟鼠标点击删除按钮
    pyautogui.click(delete_button)

def main():
    for i in range(3):
        delete_chat_info()

main()